from fastapi import FastAPI
from app.routers import users
from app.database.connection import connect_to_mongo, close_mongo_connection
from app.config import settings

app = FastAPI(
    title=settings.APP_TITLE,
    description=settings.APP_DESCRIPTION,
    version=settings.APP_VERSION
)

@app.on_event("startup")
async def startup_db_client():
    await connect_to_mongo(settings.MONGODB_URI, settings.DATABASE_NAME)

@app.on_event("shutdown")
async def shutdown_db_client():
    await close_mongo_connection()

# Include routers
app.include_router(users.router, prefix="/api/v1")

@app.get("/")
async def root():
    return {"message": "Welcome to the User Management API"}